import http from '@/http';
import type { Menu, MenuQuery, MenuForm, PageResult } from './MenuModel';

// 获取菜单树形结构
export const getMenuTree = () => {
  return http.get<Menu[]>('/api/menu/tree');
};

// 获取菜单列表（分页）
export const getMenuList = (params: MenuQuery) => {
  return http.post<PageResult<Menu>>('/api/menu/list', params);
};

// 添加菜单
export const addMenu = (data: MenuForm) => {
  return http.post<boolean>('/api/menu/add', data);
};

// 更新菜单
export const updateMenu = (data: MenuForm) => {
  return http.put<boolean>('/api/menu/update', data);
};

// 删除菜单
export const deleteMenu = (id: number) => {
  return http.delete<boolean>(`/api/menu/delete/${id}`);
};

// 批量删除菜单
export const deleteMenus = (ids: number[]) => {
  return http.delete<boolean>('/api/menu/delete/batch', { data: ids });
};

// 获取菜单详情
export const getMenuDetail = (id: number) => {
  return http.get<Menu>(`/api/menu/detail/${id}`);
};

// 获取菜单选项（用于父级菜单选择）
export const getMenuOptions = () => {
  return http.get<Menu[]>('/api/menu/options');
};

